import { combineReducers } from 'redux-immutable'; // 新的方法
// import { combineReducers } from 'redux';
import store from '../store'

import plan from './plan'
// ================================
// 同步的 Reducers（即应用初始化所必需的）
// ================================
const syncReducers = {
	planData:plan
	// userData:userReducer
}
// ================================
// 异步加载的 Reducers（Code Splitting 按需加载的）
// ================================
const asyncReducers = {}
	/**
 * @return {Function} rootReducer
 */
export const createRootReducer = () => {
	return combineReducers({
		...syncReducers,
		...asyncReducers
	})
}
/**
 * 按需加载时，立即注入对应的 Reducer
 * @param  {String}   key
 * @param  {Function} reducer
 */
export const injectReducer = (key, reducer) => {
	asyncReducers[key] = reducer
	store().replaceReducer(createRootReducer()) // 替换当前的 rootReducer
}

export default {
	...createRootReducer,
	...injectReducer
}